var tContent ;
$(function(){
    //实例化编辑器
    tContent = BLOG.createEditor("#template[name=tContent]",{
        resizeType : 1,
        minWidth : 650,
        height:315,
        allowImageUpload : true,
        items : [
            'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
            'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
            'insertunorderedlist', '|', 'emoticons',  'link','image'],
        afterCreate: function () {
            this.sync();
        },
        afterBlur:function(){this.sync();}
    });



});

var $;
var $form;
var form;
layui.config({
    base : "js/"
}).use(['form','layer','jquery','laydate'],function(){
    var layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,laydate = layui.laydate;
    $ = layui.jquery;
    form = layui.form;
    form.on("submit(addTemplate)",function(data){
        //弹出loading
        var index = layer.msg('数据提交中，请稍候',{icon: 16,time:2000,shade:0.8});
        tContent.sync("#tContent");
        $.ajax({
            type: "post",
            url: "/template/insertTemplate",
            async:false,
            // data:data.field,
            data:$("#template").serialize(),
            dataType:"json",
            success:function(data){
                if(data.code==0){
                    layer.msg(data.msg);
                    parent.location.reload();
                }else{
                    layer.msg(data.msg);
                }
            }
        });

        return false;
    })

});
layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    //指定允许上传的文件类型
    upload.render({
        elem: '#test3'
        , url: '/upload/pic'
        , accept: 'file' //普通文件
        , done: function (res) {
            alert(res.data.src);
            $("[name=tWxPhoto]").val(res.data.src);
            document.getElementById('showimg').src = res.data.src;
        }
    });
});


layui.use('upload', function () {
    var $ = layui.jquery
        , upload = layui.upload;
    //指定允许上传的文件类型
    upload.render({
        elem: '#test4'
        , url: '/upload/pic'
        , accept: 'file' //普通文件
        , done: function (res) {
            alert(res.data.src);
            $("[name=tImageUrl]").val(res.data.src);
            document.getElementById('showimg2').src = res.data.src;
        }
    });
});